import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import "./assets/style/global.css";
import i18n from "./lang/index";
import ElementUI from "element-ui";
import locale from "element-ui/lib/locale/lang/en";
import "element-ui/lib/theme-chalk/index.css";
// 引入进度条样式
import "nprogress/nprogress.css";
import china from "echarts/map/json/china.json";
import echarts from "echarts";
// 炫酷图标
import dataV from "@jiaminghi/data-view";
//引入自定义滚动条
import HappyScroll from "vue-happy-scroll";
import "vue-happy-scroll/docs/happy-scroll.css";
//自动滚动插件
import scroll from "vue-seamless-scroll";
// 炫酷的粒子动效
import VueParticles from "vue-particles";
// 全局路由守卫
import "./router/permission";
import { Message } from "element-ui";
// 全局注册指令
import vPermission from "./directive/permission";
import VueFocus from "v-focus";
// 引入懒加载指令
import { lazyImage, lazyComponent, lazyData, debounce, throttle } from "./directive/lazyLoad";
// 引入图表
import VCharts from "v-charts";
import SlideVerify from "vue-monoplasty-slide-verify";
// 引入错误处理和性能优化插件
import { ErrorHandlerPlugin } from "./utils/errorHandler";
import { performanceOptimizer } from "./utils/performanceOptimizer";
// 引入内存管理工具
import { MemoryManagerMixin } from "./utils/memoryManager";

// 注册懒加载指令
Vue.directive('lazy', lazyImage);
Vue.directive('lazy-component', lazyComponent);
Vue.directive('lazy-data', lazyData);
Vue.directive('debounce', debounce);
Vue.directive('throttle', throttle);

Vue.use(SlideVerify);
Vue.use(VCharts);
Vue.use(VueFocus);
Vue.prototype.$echarts = echarts;
echarts.registerMap("china", china);
Vue.use(dataV);
Vue.config.productionTip = false;
Vue.use(HappyScroll);
Vue.use(scroll);
Vue.use(VueParticles);

// ****************防止message同样内容多次弹出**************************
let messageInstance = null;
const overrideMessage = (options) => {
  if (messageInstance) {
    messageInstance.close();
  }
  messageInstance = Message(options);
};


["error", "success", "info", "warning"].forEach((type) => {
  Message[type] = (options) => {
    if (typeof options === "string") {
      options = {
        message: options,
      };
    }
    options.type = type;
    return overrideMessage(options);
  };
});

Vue.use(ElementUI, { locale });
//挂载
Vue.prototype.$message = overrideMessage;
// ****************《《《《《《《《《《《《《《《**************************
Vue.directive("permission", vPermission);

// 集成错误处理插件
Vue.use(ErrorHandlerPlugin);

// 在开发环境下启用性能优化
if (process.env.NODE_ENV === 'development') {
  // 在控制台暴露性能优化器，方便调试
  window.performanceOptimizer = performanceOptimizer;
}

new Vue({
  router,
  store,
  i18n,
  render: (h) => h(App),
}).$mount("#app");
